﻿@namespace Core.Web.Admin.Blazor.Pages.Setting.UserManager
@page "/setting/usermanager"
@using AntDesign.TableModels
@using Core.Web.Admin.Blazor.Models.System.User
<PageContainer Title="用户管理">
    <Breadcrumb>
        <Breadcrumb>
            <BreadcrumbItem>系统设置</BreadcrumbItem>
            <BreadcrumbItem>用户管理</BreadcrumbItem>
        </Breadcrumb>
    </Breadcrumb>
    <ChildContent>
        <Card Title="数据筛选">
            <Row Gutter="24">
                <AntDesign.Col Sm="3" Xs="10">
                    <Input Placeholder="请输入账户/手机号/邮箱" @bind-Value="userName" />
                </AntDesign.Col>
                <AntDesign.Col Sm="3" Xs="10">
                    <Input Placeholder="请输入账户/手机号/邮箱" @bind-Value="userName" />
                </AntDesign.Col>
                <AntDesign.Col Sm="8" Xs="10">
                    <Input Placeholder="请输入账户/手机号/邮箱" @bind-Value="userName" />
                </AntDesign.Col>
                <AntDesign.Col Sm="8" Xs="10">
                    <Input Placeholder="请输入账户/手机号/邮箱" @bind-Value="userName" />
                </AntDesign.Col>
                <Button Type="@ButtonType.Primary" Icon="@IconType.Outline.Search">Search</Button>
            </Row>

        </Card>

        <Card Class="listCard" Style="margin-top: 24px;" Title="数据列表">
            <Space Size="@("middle")">
                <SpaceItem>
                    <Button Type="@ButtonType.Primary" style="float:right">添加</Button>
                </SpaceItem>
                <SpaceItem>
                    <Button Danger Type="@ButtonType.Primary" style="float:right">删除</Button>
                </SpaceItem>
            </Space>
            <h5>
                selections:
                @if (selectedRows != null)
                {
                    @foreach (var selected in selectedRows)
                    {
                        <Tag @key="selected" Closable OnClose="e=>RemoveSelection(selected.Account)">@selected.Account</Tag>
                    }
                    <Button Danger Size="small" OnClick="@(e => { table.SetSelection(null); })">Clear</Button>
                }
            </h5>
            <AntDesign.Table @ref="table" TItem="AdminUser" DataSource="@data" Total="pagerInfo.RecordCount"
                             @bind-PageIndex="pagerInfo.CurrenetPageIndex" @bind-PageSize="pagerInfo.PageSize" OnChange="OnChange"
                             @bind-SelectedRows="selectedRows">
                <Selection Key="@context.Account" Type="@selectionType" Disabled="@(context.Account=="Disabled User")" />
                <AntDesign.Column @bind-Field="@context.Avatar">
                    <Avatar Size="64" Src="@context.Avatar" Icon="user" />
                </AntDesign.Column>
                <AntDesign.Column DataIndex="@nameof(context.Account)" TData="string">
                    <a>@context.Account</a>
                </AntDesign.Column>
                <AntDesign.Column @bind-Field="@context.Role">
                    @foreach (var tag in context.Role.Split(','))
                    {

                        var random = (PresetColor)_random.Next(0, 12);
                        <Tag PresetColor="@random">@tag</Tag>
                    }
                </AntDesign.Column>
                <AntDesign.Column @bind-Field="@context.Email"></AntDesign.Column>
                <AntDesign.Column @bind-Field="@context.PhoneNumber"></AntDesign.Column>
                <AntDesign.Column @bind-Field="@context.TrueName"></AntDesign.Column>
                <AntDesign.Column @bind-Field="@context.Address"></AntDesign.Column>
                <AntDesign.Column @bind-Field="@context.Company"></AntDesign.Column>
                <ActionColumn Title="Action">
                    <Space Size=@("middle")>
                        <SpaceItem>
                            <a>修改</a>
                        </SpaceItem>
                        <SpaceItem>
                            <Popconfirm Title="Are you sure delete this task?"
                                        OnConfirm="()=>Delete(context.Id)"
                                        OnCancel="Cancel"
                                        OkText="Yes"
                                        CancelText="No">
                                <a>Delete</a>
                            </Popconfirm>
                        </SpaceItem>
                    </Space>
                </ActionColumn>
            </AntDesign.Table>
        </Card>
    </ChildContent>
</PageContainer>